<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\cost;

use app\enum\CommonEnum;
use app\service\BaseService;
use app\service\cost\pull\KsService;
use app\service\cost\pull\OceanService;
use app\service\cost\pull\QqService;

final class PullService extends BaseService
{
    private ?BaseService $handle;

    public function __construct($mediaId = 0)
    {
        if ($mediaId == CommonEnum::OE_MEDIA) {
            $this->handle = new OceanService();
        } elseif ($mediaId == CommonEnum::KS_MEDIA) {
            $this->handle = new KsService();
        } elseif ($mediaId == CommonEnum::QQ_MEDIA) {
            $this->handle = new QqService();
        }
    }

    /**
     * 魔法函数调用媒体接口.
     * @return bool|void
     */
    public function __call($name, $arguments)
    {
        if (! method_exists($this->handle, $name)) {
            return self::setError('方法未定义');
        }
        return call_user_func_array([$this->handle, $name], $arguments);
    }

    /**
     * 判断服务.
     * @return bool
     */
    public function isPullService(): bool
    {
        return $this->handle instanceof BaseService;
    }
}
